import VueRouter from "vue-router";
import Login from "@/components/Login";
import Index from "@/components/index";
import Users from "@/components/users";
import Role from "@/components/role";
import Hello from "@/components/hello"
import Rk from "@/components/Rk";
import Ck from "@/components/Ck";
import Staff from "@/components/staff";
import products from "@/components/products";
import Procurement from "@/components/Procurement";
import Productstype from "@/components/Productstype";

const router=new VueRouter({
    routes:[
        {path:"/",component:Login},
        {path: "/index",component: Index,
            children:[
                {path: "/",component: Hello},
                {path: "/users",component: Users},
                {path: "/role",component: Role},
                {path: "/rk",component: Rk},
                {path: "/ck",component: Ck},
                {path: "/staff",component: Staff},
                {path: "/products",component: products},
                {path: "/procurement",component: Procurement},
                {path: "/productstype",component: Productstype}
            ]
        },
    ]
});

//导航守卫
router.beforeEach((to, from, next) =>{
    let user = sessionStorage.getItem("sessionStorage_user");
    if (!user && to.path!="/"){
        next("/")
    }else {
        next()
    }
})

export default router;